use Archive::Zip;
# ppm install Archive-Zip
my ($sec,$min,$hour,$mday,$month,$year,$youbi,$yday,$isdst)=localtime();
my $fileName1 = sprintf("../SRC-ExplodeRunnerD-%02d%02d%02d.zip" , $year%100 , ($month+1) , $mday);
my $fileName2 = sprintf("../ExplodeRunnerWin-%02d%02d%02d.zip"     , $year%100 , ($month+1) , $mday);
my $fileName3 = sprintf("../ExplodeRunnerMac-%02d%02d%02d.zip"     , $year%100 , ($month+1) , $mday);

sub makeSrc() {
	my $fileName = $_[0];
	unlink $fileName;
	print "make $fileName\n";
	my $zip = Archive::Zip->new();
	$zip->addTree('.');
	$zip->removeMember('make.exe');
	$zip->removeMember('config.ini.bk');
	$zip->removeMember('config.ini');
	$zip->removeMember('Explode.map');
	$zip->removeMember('log.txt');
	$zip->removeMember('makezip.bat');
	$zip->removeMember("SDL.dll");
	$zip->removeMember("SDL_mixer.dll");

	$zip->writeToFileNamed($fileName);
} #

sub makeExe() {
	my $fileName = $_[0];
	unlink $fileName;
	print "make $fileName\n";
	my $zip = Archive::Zip->new();
	$zip->addTree('_data/img'  ,'_data/img');
	$zip->addTree('_data/sound','_data/sound');
	$zip->addTree('_data/stage','_data/stage');
	$zip->addTree('resource' , 'resource');
	
	opendir DB,".";
	foreach( readdir( DB ) ) {
		if ( m/\.txt$/ ) {
#			print "$_\n";
			$zip->addFile($_);
		}
	}
	closedir DB;
	$zip->addFile("Explode.exe");
	$zip->addFile("Explode.scr");
#	$zip->addFile("操作方法.txt");
#	$zip->addFile("D言語ゲームライブラリ「dHell2」.txt");
	$zip->addFile("*.txt");
	$zip->addFile("SDL.dll");
	$zip->addFile("SDL_mixer.dll");
	$zip->removeMember("log.txt");
	$zip->removeMember("params.txt");

	for ( $i = 6 ; $i < 1000 ; $i++ ) {
		$fn = sprintf("_data/stage/replay/stage%04d.txt" , $i );
		if ( -e $fn ) { $zip->removeMember( $fn ); }
	}

	$zip->writeToFileNamed($fileName);
} #


sub makeMac() {
	my $fileName = $_[0];
	unlink $fileName;
	print "make $fileName\n";
	my $zip = Archive::Zip->new();
	$zip->addTree('_data/img'  ,'_data/img');
	$zip->addTree('_data/sound','_data/sound');
	$zip->addTree('_data/stage','_data/stage');
	$zip->addTree('resource' , 'resource');
	
	opendir DB,".";
	foreach( readdir( DB ) ) {
		if ( m/\.txt$/ ) {
#			print "$_\n";
			$zip->addFile($_);
		}
	}
	closedir DB;
	$zip->addFile("ExplodeRunner");
#	$zip->addFile("操作方法.txt");
#	$zip->addFile("D言語ゲームライブラリ「dHell2」.txt");
	$zip->addFile("*.txt");
	$zip->removeMember("log.txt");
	$zip->removeMember("params.txt");

	for ( $i = 6 ; $i < 1000 ; $i++ ) {
		$fn = sprintf("_data/stage/replay/stage%04d.txt" , $i );
		if ( -e $fn ) { $zip->removeMember( $fn ); }
	}

	$zip->writeToFileNamed($fileName);
} #


&makeSrc($fileName1);
&makeExe($fileName2);
&makeMac($fileName3);
